import React, { useEffect, useState } from "react";
import { Tabs } from "antd";
import { List } from "../../utils/index";
import Listdata from "../../components/Listdata";
function Home() {
  const [data, setData] = useState({});
  const [loading, setLoading] = useState(false);
  const [params, setParams] = useState({
    page: 1, //页码
    pageSize: 6, //每页显示条数
    keyword: null, //搜索标题
    tag: null, //搜索标签
  });
  useEffect(() => {
    ListData();
  }, [params]);
  const ListData = async () => {
    setLoading(true);
    try {
      const res = await List(params);
      setData(res);
    } finally {
      setLoading(false);
    }
  };
  const items = [
    {
      label: "推荐",
      key: null,
    },
    // {
    //   label: "Node",
    //   key: "Node",
    // },
    {
      label: "最新",
      key: "HTTP",
    },
  ];
  const onChange = (tag) => {
    tag = tag === "null" ? null : tag;
    console.log(typeof tag);
    setParams((prev) => ({ ...prev, tag, page: 1 }));
  };
  return (
    <div>
      <div>
        <Tabs defaultActiveKey="" items={items} onChange={onChange} />
      </div>
      <div>
        <Listdata
          data={data}
          loading={loading}
          onPageChange={(page) => setParams((prve) => ({ ...prve, page }))}
          current={params.page}
        ></Listdata>
      </div>
    </div>
  );
}

export default Home;
